package com.nimitz.web.controller.module.employee;

import com.nimitz.common.annotation.Log;
import com.nimitz.common.core.controller.BaseController;
import com.nimitz.common.core.domain.AjaxResult;
import com.nimitz.common.core.page.TableDataInfo;
import com.nimitz.common.enums.BusinessType;
import com.nimitz.common.utils.StringUtils;
import com.nimitz.module.employee.domain.EmpOfficial;
import com.nimitz.module.employee.service.IEmpOfficialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 转正维护
 */
@RestController
@Api(tags = "人员管理-转正记录")
@RequestMapping("/module/employee/official")
public class EmpOfficialController extends BaseController {

    @Resource
    private IEmpOfficialService officialService;

    /**
     * 根据转正id查询转正
     *
     * @param officialId 转正id
     * @return 转正
     */
    @GetMapping("/{officialId}")
    @ApiOperation(value = "根据转正id查询转正")
    public AjaxResult getInfo(@PathVariable(value = "officialId", required = false) Integer officialId) {
        AjaxResult ajax = AjaxResult.success();
        if (StringUtils.isNotNull(officialId)) {
            EmpOfficial official = officialService.selectOfficialById(officialId);
            ajax.put(AjaxResult.DATA_TAG, official);
        }
        return ajax;
    }

    /**
     * 根据条件查询转正列表（含分页）
     *
     * @param official 转正
     * @return 转正集合
     */
    @PostMapping("/list")
    @PreAuthorize("@ss.hasPermi('employee:official:list')")
    @ApiOperation(value = "根据条件查询转正列表（含分页）")
    public TableDataInfo list(@RequestBody EmpOfficial official) {
        startPage();
        List<EmpOfficial> list = officialService.selectOfficialList(official);
        return getDataTable(list);
    }

    /**
     * 批量审核
     *
     * @param officialIds 需要驳回的转正id集合
     * @return 结果
     */
    @PutMapping("/audit/{officialIds}")
    @ApiOperation(value = "批量审核")
    @PreAuthorize("@ss.hasPermi('employee:official:audit')")
    @Log(title = "转正审核", businessType = BusinessType.UPDATE)
    public AjaxResult audit(@PathVariable Integer[] officialIds) {
        return toAjax(officialService.auditOfficial(getUsername(), officialIds));
    }
}
